<?php

namespace App\Http\Middleware;

use App\Facade\AppContext;
use App\Utils\Output;
use Closure;
use Illuminate\Http\Request;

class Hospital
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!AppContext::hospitalId()) {
            if ($request->ajax()) {
                return response()->json(Output::fail('未选择医院', Output::NO_HOSPITAL));
            } else {
                return response(view('admin.error')->with('msg', '未选择医院'));
            }
        }
        return $next($request);
    }
}